package kr.saeildamil.androidStudy_second.fragment.network;

import java.util.ArrayList;

import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	ArrayList<Item> itemList;
	Context context;

	public MyAdapter(ArrayList<Item> itemList, Context context) {
		super();
		this.itemList = itemList;
		this.context = context;
	}
	public int getCount() {return itemList.size();}
	public Object getItem(int position) {return itemList.get(position);}
	public long getItemId(int position) {return position;}

	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout layout = null;
		TextView itemName = null;
		TextView makeName = null;
		TextView itemPrice = null;
		
		if(convertView==null){
			layout = new LinearLayout(context);
			layout.setOrientation(LinearLayout.HORIZONTAL);
			itemName = new TextView(context);
			makeName = new TextView(context);
			itemPrice = new TextView(context);
			LayoutParams params = new LayoutParams(
					LinearLayout.LayoutParams.WRAP_CONTENT,
					LinearLayout.LayoutParams.WRAP_CONTENT);
			layout.addView(itemName, params);
			layout.addView(makeName, params);
			layout.addView(itemPrice, params);			
		}
		
		itemName.setText(itemList.get(position).getItemName());
		makeName.setText(itemList.get(position).getMakeName());
		itemPrice.setText(Integer.toString(itemList.get(position).getItemPrice()));
		
		return layout;
	}

}
